package com.ruoyi.web.controller.ydd;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ydd.domain.BusMaterialmanage;
import com.ruoyi.ydd.service.IBusMaterialmanageService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物资管理Controller
 *
 * @author ruoyi
 * @date 2022-09-04
 */
@Controller
@RequestMapping("/ydd/materialmanage")
public class BusMaterialmanageController extends BaseController
{
    private String prefix = "system/materialmanage";

    @Autowired
    private IBusMaterialmanageService busMaterialmanageService;

//    @RequiresPermissions("ydd:materialmanage:view")
    @GetMapping()
    public String materialmanage()
    {
        return prefix + "/materialmanage";
    }

    /**
     * 查询物资管理列表
     */
//    @RequiresPermissions("ydd:materialmanage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BusMaterialmanage busMaterialmanage)
    {
        startPage();
        List<BusMaterialmanage> list = busMaterialmanageService.selectBusMaterialmanageList(busMaterialmanage);
        return getDataTable(list);
    }

    /**
     * 导出物资管理列表
     */
//    @RequiresPermissions("ydd:materialmanage:export")
    @Log(title = "物资管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusMaterialmanage busMaterialmanage)
    {
        List<BusMaterialmanage> list = busMaterialmanageService.selectBusMaterialmanageList(busMaterialmanage);
        ExcelUtil<BusMaterialmanage> util = new ExcelUtil<BusMaterialmanage>(BusMaterialmanage.class);
        return util.exportExcel(list, "物资管理数据");
    }

    /**
     * 新增物资管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存物资管理
     */
    @Log(title = "物资管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusMaterialmanage busMaterialmanage)
    {
        return toAjax(busMaterialmanageService.insertBusMaterialmanage(busMaterialmanage));
    }

    /**
     * 修改物资管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BusMaterialmanage busMaterialmanage = busMaterialmanageService.selectBusMaterialmanageById(id);
        mmap.put("busMaterialmanage", busMaterialmanage);
        return prefix + "/edit";
    }

    /**
     * 修改保存物资管理
     */
    @Log(title = "物资管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BusMaterialmanage busMaterialmanage)
    {
        return toAjax(busMaterialmanageService.updateBusMaterialmanage(busMaterialmanage));
    }

    /**
     * 删除物资管理
     */
    @Log(title = "物资管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(busMaterialmanageService.deleteBusMaterialmanageByIds(ids));
    }
}
